﻿using System;
using System.Windows;
using System.Windows.Controls;
using Silvery;
using Silvery.Role.Simple;

namespace Sample02_Role
{
    public class Sample_3 : GameRoot
    {
        public static Random random = new Random((int)DateTime.Now.Ticks);
        private SimpleRole_Monster monster;
        public Sample_3()
        {
            
            monster = new SimpleRole_Monster(new Uri("download/Sample_Role/Monster01.zip", UriKind.Relative));
            this.AddBaseObj(monster);
            monster.Position = new Point(150, 100);

            Button addtest = new Button() {Content = "添加一个试试" };
            addtest.Click += new RoutedEventHandler(addtest_Click);
            this.Children.Add(addtest);
        }

        void addtest_Click(object sender, RoutedEventArgs e)
        {
            var t = new SimpleRole_Monster(new Uri("download/Sample_Role/Monster01.zip", UriKind.Relative));
            this.AddBaseObj(t);
            t.Position = new Point(random.Next() % 500 + 40, random.Next() % 300 + 60);
        }
        public class SimpleRole_Monster : SimpleRole
        {
            ComboBox combobox = new ComboBox() { Width = 72 };
            public SimpleRole_Monster(Uri uri)
                : base(uri)
            {
                MouseEnterEffectOpened = true;
                RoleName = "我是一个演示怪物";
                this.Children.Add(combobox);
                Canvas.SetLeft(combobox, -36);
                Canvas.SetTop(combobox, 40);
                combobox.SelectionChanged += new SelectionChangedEventHandler(combobox_SelectionChanged);
                base.BeginDownload();
            }

            void combobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                this.CurrentAnimatName = (string)combobox.SelectedItem;
            }
            protected override void OnBodyPackLoaded()
            {
                foreach (var item in BodyPart.SpiritData.AnimatNamesList)
                {
                    combobox.Items.Add(item);
                }
                var rm = Sample_3.random.Next() % combobox.Items.Count;
                combobox.SelectedIndex = rm;
                if (CurrentAnimatName == null)
                    CurrentAnimatName = (string)combobox.Items[rm];
                base.OnBodyPackLoaded();
            }
        }
    }
    
}
